package org.tigris.subversion.svnant;

import java.io.CharArrayWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Reference;
import org.tigris.subversion.svnant.commands.Add;
import org.tigris.subversion.svnant.commands.Cat;
import org.tigris.subversion.svnant.commands.Checkout;
import org.tigris.subversion.svnant.commands.Cleanup;
import org.tigris.subversion.svnant.commands.Commit;
import org.tigris.subversion.svnant.commands.Copy;
import org.tigris.subversion.svnant.commands.CreateRepository;
import org.tigris.subversion.svnant.commands.Delete;
import org.tigris.subversion.svnant.commands.Diff;
import org.tigris.subversion.svnant.commands.Export;
import org.tigris.subversion.svnant.commands.Feedback;
import org.tigris.subversion.svnant.commands.Ignore;
import org.tigris.subversion.svnant.commands.Import;
import org.tigris.subversion.svnant.commands.Info;
import org.tigris.subversion.svnant.commands.Keywordsadd;
import org.tigris.subversion.svnant.commands.Keywordsremove;
import org.tigris.subversion.svnant.commands.Keywordsset;
import org.tigris.subversion.svnant.commands.Log;
import org.tigris.subversion.svnant.commands.Mkdir;
import org.tigris.subversion.svnant.commands.Move;
import org.tigris.subversion.svnant.commands.Propdel;
import org.tigris.subversion.svnant.commands.Propget;
import org.tigris.subversion.svnant.commands.Propset;
import org.tigris.subversion.svnant.commands.Revert;
import org.tigris.subversion.svnant.commands.SingleInfo;
import org.tigris.subversion.svnant.commands.Status;
import org.tigris.subversion.svnant.commands.SvnCommand;
import org.tigris.subversion.svnant.commands.Switch;
import org.tigris.subversion.svnant.commands.Update;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.ISVNNotifyListener;

public class SvnTask extends Task
{
  private static final String MSG_DEPRECATION = "Deprecated attribute '%s'. This attribute will disappear with SVNANT 1.3.2. Use svnSetting instead.";
  private java.util.List<SvnCommand> commands = new ArrayList();
  private java.util.List<ISVNNotifyListener> notifyListeners = new ArrayList();
  private CharArrayWriter writer = new CharArrayWriter();
  private PrintWriter printer = new PrintWriter(this.writer);
  private PrintWriter logprinter = null;
  private File logfile = null;

  public void setLogFile(File paramFile)
  {
    this.logfile = paramFile;
  }

  public ProjectComponent getProjectComponent()
  {
    return this;
  }

  public void setRefid(Reference paramReference)
  {
    SvnFacade.setRefid(this, paramReference);
  }

  public void setUsername(String paramString)
  {
    warning("Deprecated attribute '%s'. This attribute will disappear with SVNANT 1.3.2. Use svnSetting instead.", new Object[] { "username" });
    SvnFacade.setUsername(this, paramString);
  }

  public void setPassword(String paramString)
  {
    warning("Deprecated attribute '%s'. This attribute will disappear with SVNANT 1.3.2. Use svnSetting instead.", new Object[] { "password" });
    SvnFacade.setPassword(this, paramString);
  }

  public void setJavahl(boolean paramBoolean)
  {
    warning("Deprecated attribute '%s'. This attribute will disappear with SVNANT 1.3.2. Use svnSetting instead.", new Object[] { "javahl" });
    SvnFacade.setJavahl(this, paramBoolean);
  }

  public void setSvnkit(boolean paramBoolean)
  {
    warning("Deprecated attribute '%s'. This attribute will disappear with SVNANT 1.3.2. Use svnSetting instead.", new Object[] { "svnkit" });
    SvnFacade.setSvnKit(this, paramBoolean);
  }

  public void setDateFormatter(String paramString)
  {
    warning("Deprecated attribute '%s'. This attribute will disappear with SVNANT 1.3.2. Use svnSetting instead.", new Object[] { "dateformatter" });
    SvnFacade.setDateFormatter(this, paramString);
  }

  public void setDateTimezone(String paramString)
  {
    warning("Deprecated attribute '%s'. This attribute will disappear with SVNANT 1.3.2. Use svnSetting instead.", new Object[] { "datetimezone" });
    SvnFacade.setDateTimezone(this, paramString);
  }

  public void setFailonerror(boolean paramBoolean)
  {
    warning("Deprecated attribute '%s'. This attribute will disappear with SVNANT 1.3.2. Use svnSetting instead.", new Object[] { "failonerror" });
    SvnFacade.setFailonerror(this, paramBoolean);
  }

  public void addCheckout(Checkout paramCheckout)
  {
    addCommand(paramCheckout);
  }

  public void addSingleinfo(SingleInfo paramSingleInfo)
  {
    addCommand(paramSingleInfo);
  }

  public void addList(org.tigris.subversion.svnant.commands.List paramList)
  {
    addCommand(paramList);
  }

  public void addAdd(Add paramAdd)
  {
    addCommand(paramAdd);
  }

  public void addCleanup(Cleanup paramCleanup)
  {
    addCommand(paramCleanup);
  }

  public void addCommit(Commit paramCommit)
  {
    addCommand(paramCommit);
  }

  public void addCopy(Copy paramCopy)
  {
    addCommand(paramCopy);
  }

  public void addDelete(Delete paramDelete)
  {
    addCommand(paramDelete);
  }

  public void addExport(Export paramExport)
  {
    addCommand(paramExport);
  }

  public void addInfo(Info paramInfo)
  {
    addCommand(paramInfo);
  }

  public void addImport(Import paramImport)
  {
    addCommand(paramImport);
  }

  public void addLog(Log paramLog)
  {
    addCommand(paramLog);
  }

  public void addMkdir(Mkdir paramMkdir)
  {
    addCommand(paramMkdir);
  }

  public void addMove(Move paramMove)
  {
    addCommand(paramMove);
  }

  public void addUpdate(Update paramUpdate)
  {
    addCommand(paramUpdate);
  }

  public void addPropset(Propset paramPropset)
  {
    addCommand(paramPropset);
  }

  public void addDiff(Diff paramDiff)
  {
    addCommand(paramDiff);
  }


  public void addKeywordsSet(Keywordsset paramKeywordsset)
  {
    addCommand(paramKeywordsset);
  }

  public void addKeywordsAdd(Keywordsadd paramKeywordsadd)
  {
    addCommand(paramKeywordsadd);
  }

  public void addKeywordsRemove(Keywordsremove paramKeywordsremove)
  {
    addCommand(paramKeywordsremove);
  }

  public void addRevert(Revert paramRevert)
  {
    addCommand(paramRevert);
  }

  public void addCat(Cat paramCat)
  {
    addCommand(paramCat);
  }

  public void addPropdel(Propdel paramPropdel)
  {
    addCommand(paramPropdel);
  }

  public void addIgnore(Ignore paramIgnore)
  {
    addCommand(paramIgnore);
  }

  public void addCreateRepository(CreateRepository paramCreateRepository)
  {
    addCommand(paramCreateRepository);
  }


  public void addStatus(Status paramStatus)
  {
    addCommand(paramStatus);
  }

  public void addSwitch(Switch paramSwitch)
  {
    addCommand(paramSwitch);
  }

  public void addPropget(Propget paramPropget)
  {
    addCommand(paramPropget);
  }

  private void addCommand(SvnCommand paramSvnCommand)
  {
    paramSvnCommand.setTask(this);
    this.commands.add(paramSvnCommand);
  }

  public void addNotifyListener(ISVNNotifyListener paramISVNNotifyListener)
  {
    this.notifyListeners.add(paramISVNNotifyListener);
  }

  private Object[] alter(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject != null)
      for (int i = 0; i < paramArrayOfObject.length; i++)
      {
        if (!(paramArrayOfObject[i] instanceof Throwable))
          continue;
        this.writer.reset();
        Throwable localThrowable = (Throwable)paramArrayOfObject[i];
        localThrowable.printStackTrace(this.printer);
        paramArrayOfObject[i] = String.valueOf(this.writer.toCharArray());
      }
    return paramArrayOfObject;
  }

  public void verbose(String paramString, Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject == null) || (paramArrayOfObject.length == 0))
      write(paramString, 3);
    else
      write(String.format(paramString, alter(paramArrayOfObject)), 3);
  }

  public void debug(String paramString, Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject == null) || (paramArrayOfObject.length == 0))
      write(paramString, 4);
    else
      write(String.format(paramString, alter(paramArrayOfObject)), 4);
  }

  public void warning(String paramString, Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject == null) || (paramArrayOfObject.length == 0))
      write(paramString, 1);
    else
      write(String.format(paramString, alter(paramArrayOfObject)), 1);
  }

  public void info(boolean paramBoolean, String paramString, Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject == null) || (paramArrayOfObject.length == 0))
      write(paramString, paramBoolean ? 3 : 2);
    else
      write(String.format(paramString, alter(paramArrayOfObject)), paramBoolean ? 3 : 2);
  }

  public void info(String paramString, Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject == null) || (paramArrayOfObject.length == 0))
      write(paramString, 2);
    else
      write(String.format(paramString, alter(paramArrayOfObject)), 2);
  }

  public void error(String paramString, Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject == null) || (paramArrayOfObject.length == 0))
      write(paramString, 0);
    else
      write(String.format(paramString, alter(paramArrayOfObject)), 0);
  }

  private void write(String paramString, int paramInt)
  {
    if (this.logprinter != null)
      this.logprinter.println(paramString);
    else
      log(paramString, paramInt);
  }

  public void execute()
    throws BuildException
  {
    try
    {
      if (this.logfile != null)
        this.logprinter = new PrintWriter(new FileWriter(this.logfile));
      executeImpl();
    }
    catch (Exception localException)
    {
      if (SvnFacade.getFailonerror(this))
      {
        if ((localException instanceof BuildException))
          throw ((BuildException)localException);
        throw new BuildException(localException);
      }
      error("the execution failed for some reason. cause: %s", new Object[] { localException });
    }
    finally
    {
      if (this.logprinter != null)
        this.logprinter.close();
    }
  }

  private void executeImpl()
  {
    ISVNClientAdapter localISVNClientAdapter = SvnFacade.getClientAdapter(this);
    for (int i = 0; i < this.notifyListeners.size(); i++)
      localISVNClientAdapter.addNotifyListener((ISVNNotifyListener)this.notifyListeners.get(i));
    for (int i = 0; i < this.commands.size(); i++)
    {
      SvnCommand localSvnCommand = (SvnCommand)this.commands.get(i);
      Feedback localFeedback = new Feedback(localSvnCommand);
      localISVNClientAdapter.addNotifyListener(localFeedback);
      localSvnCommand.executeCommand(localISVNClientAdapter);
      localISVNClientAdapter.removeNotifyListener(localFeedback);
    }
  }
}

/* Location:           C:\Users\Administrator\Desktop\svnant.jar
 * Qualified Name:     org.tigris.subversion.svnant.SvnTask
 * JD-Core Version:    0.6.0
 */